class Student {
    fullName: string;

    constructor(public firstName, public middleInitial, public lastName) {
        this.fullName = firstName + " " + middleInitial + " " + lastName;
    }
}

interface Person {
    firstName: string;
    lastName: string;
}

function greeter(person: Person) {
    return "Hello, " + person.firstName + " " + person.lastName;
}

let user = new Student("Jane", "M.", "User");

// document.body.innerHTML = greeter(user);

let isDone: boolean = false;

let lala: number = 0X66;

let name1: string = "sss:";
let name2 = "lalalalal";
name2 = "1234567890";
console.log(name1 + "    ----     " + name2);
let age: number = 12;

var name3 = ` Hello Java , this.name = ${ name2 } ` + name2;
console.log(name3);

let sentence: string = `Hello, my name is ${ name1 }. I'll be ${ age + 1 } years old next month.`;
console.log(sentence);

let list: number [] = [1, 2, 3];

let list2: number[] = [1, 2, 3, 4];
list2.push(5);
let la = list2.indexOf(0, 3);
console.log(list);
console.log(list2);
console.log(la);

let list3: Array<number> = [1.2, 2.3, 4, 5, 6];
console.log(list3);

let x: [string, number] = ["songxiankun", 100];

console.log(x);

console.log(x[0].substr(3));

x[3] = "2008@126.com";
x[4] = 999;
console.log(x.toString() + "     ?");

console.log(x.toString());


// let c: Color = Color.Green;
// console.log(c);
//
// let sad: String = Color[1];
// console.log(sad);
const lalala: number = 88;

function f() {
    var a = 10;
    return function g() {
        var b = a + 1;
        return b;
    }
}

let g = f();
g();
try {
} catch (e) {
    console.log(e);
} finally {
}

function ff(number, String) {
    let qw = 123;
    return qw;
}

console.log(ff);

function f2(condition, x) {
    if (condition) {
        let x = 100;
        return x;
    }

    return x;
}

f2(false, 0); // returns 0
f2(true, 0);  // returns 100

function sumMatrix(matrix: number[][]) {
    console.log(matrix.toString() + "     ...." + matrix.length);
    let sum = 0;
    for (let i = 0; i < matrix.length; i++) {
        var currentRow = matrix[i];
        for (let i = 0; i < currentRow.length; i++) {
            sum += currentRow[i];
        }
    }

    return sum;
}

let po = [[123], [456]]
console.log(sumMatrix(po) + "          po");

let input = [1, 2, 99];
let [first, second, sha] = input;
console.log(first); // outputs 1
console.log(second); // outputs 2
console.log(sha);

[sha, first, second] = [first, sha, second]
/**** swap variables ***/
console.log("first=" + first + ",sha=" + sha + ",second=" + second);

/**** 这个厉害了 ***/

function f3([first, second]: [number, number]) {
    console.log(first);
    console.log(second);
}

function f4([a, b, c, d, e]: [number, Student, String, boolean, number[][]], String) {
}

let [ggg, ...ppp] = [1, 2, 3, 4, 5];
console.log(ggg + "    =>单个数字");
console.log(ppp + "  =>这是一个简单的集合");

function keepWholeObject(wholeObject: { a: string, b?: number }) {
    let {a, b = 1001} = wholeObject;
}

let first1 = [1, 2];
let second1 = [3, 4];
let bothPlus = [0, ...first1, ...second1, 5];
console.log(bothPlus);

/**** 完全没懂是啥意思 ***/
function printLabel(labelledObj: { label: string }) {
    console.log(labelledObj.label);
}

let myObj = {size: 10, label: "Size 10 Object"};
printLabel(myObj);

let xixi: any = 123;
xixi = "La La La";
console.log("这是xixi:" + xixi);


function f1(): void {
    /**** 这是一个没有返回值的方法 ***/
    console.log("这是一个没有返回值的方法");
}

function f5(name: String): String {
    return "";
}

class person {
    name: String;
    age: number;
}

let person1: person = new person();
person1.age = 18;
person1.name = "lisi";
console.log("person =>> " + person1.name + "  |   " + person1.age);

function f6(a: String, b: String, c: String = "这是一个默认值") {

}

f6("aaa", "bbb", "ccc");
/**** 有默认值的就可以不用传 ？ ***/
f6("ddd", "eee",);

function f7(a: String, b?: String, c: String = "why ") {
    console.log(b.length);
    console.log("如果  b    没有参数可以传入的话,那么此处就会报错");

}

/**** 按照顺序传入参数,带问号表示是可选参数传入,第三个参数就必须要强制设置成默认值 ？！  ***/
f7("aaa", "bbb", "cccwhy ???");

// f7("ssssss");
/**** 此处没有传入第二个参数,Error : Exception ***/
function f8(...args) {
    args.forEach(function (arg) {
        console.log(arg);
    });
}

function f9(...啦) {
    啦.forEach(function (拉) {
        console.log(拉);
    });
    for (let i = 0; i < 啦.length; i++) {
        console.log(啦[i]);
    }
}

let arrrr = [99, 88, 77, 66.55, 123.54, 999999999999, 88.123456789];
f9(arrrr);

/****     yield() 和  next()   这两个方法怎么没有  ???  ***/

var ll = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var [, , b, a] = ll;
console.log(a);
console.log(b);
let [c, d, ...others] = ll;
console.log(c);
console.log(d);
console.log(others);

/**** ---------------------------------------------- ***/

class personOne {
    public name: String = null;


    constructor() {
        console.log(" this is 构造器！？");
        this.name = name
        ;
    }


    public eat() {
        console.log("what?");
    }

    protected lalala() {
        let personOne1 = new personOne();
        personOne1.eat();
        personOne1.lalala();
        while (false) {
            return;
        }
    }
}

let one = new personOne();
one.name = "zhangsan";
one.eat();
let two = new personOne();
two.name = "lisi";
two.eat();

class Me extends personOne {
    constructor(name: String, Id: Number) {
        super();
    }

    lalala() {
        console.log("继承方法!");
        ;
    }
}

new Me("songxiankun2008@126.com", 18);

interface SearchFunc {
    (source: string, subString: string): boolean;
}

let mySearch: SearchFunc;
mySearch = function (source: string, subString: string) {
    let result = source.search(subString);
    return result > -1;
}


interface ClockConstructor {
    new(hour: number, minute: number): ClockInterface;
}

interface ClockInterface {
    tick();
}

function createClock(ctor: ClockConstructor, hour: number, minute: number): ClockInterface {
    return new ctor(hour, minute);
}

class DigitalClock implements ClockInterface {
    constructor(h: number, m: number) {
    }

    tick() {
        console.log("beep beep");
    }
}

class AnalogClock implements ClockInterface {
    constructor(h: number, m: number) {
    }

    tick() {
        console.log("tick tock");
    }
}

let digital = createClock(DigitalClock, 12, 17);
let analog = createClock(AnalogClock, 7, 32);